<%-- 
    Document   : form
    Created on : Feb 8, 2014, 7:00:32 PM
    Author     : Marek
--%>

<%@page import="entities.users.FormSigner"%>
<%@page import="entities.tools.Form"%>
<%@page import="util.other.ENUMQuestionTypes"%>
<%@page import="entities.tools.Question"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="false" %> 
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    //Session global vars
    //form
    //formSigner
    //questions
//TODO: I'm searching for the way to use enum as a key used, whan i'm reading, session vars. I need to use this enum in easy way, and in easy way perform refactor operation on this enum, without performing changes to jsp code
/*
<c:set var="form" value="${filledForm.form}"/>
<c:set var="formSigner" value="${filledForm.formSigner}"/>
<c:set var="questions" value="${form.questions}"/>*/
%>
<c:url var="formAction" value="">
    <c:param name="action" value="form"/>
</c:url>

<c:set var="form" value="${filledForm.form}"/>
<c:set var="formSigner" value="${filledForm.formSigner}"/>
<c:set var="questions" value="${form.questions}"/>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>${form.name}</title>
            <link href="<c:url value="/CSS/global.css"/>" rel="stylesheet" type="text/css"/>            
    </head>
    <body class="body">
        <div class="page">
        <form class="form" name="form-${form.id}" method="POST" action="${formAction}" id="form-${form.id}">
            <div class="formContainer">
                <img src="<c:url value="/CSS/logo.png"/>" class="formLogo" alt="insert the logo here"/>
                <input name="formName" value="form" type="hidden"/>
                <input name="formId" value="${form.id}" type="hidden"/>
                <input name="formSignerId" value="${formSigner.id}" type="hidden"/>
                <input name="linkHash" value="${linkHash}" type="hidden"/>

                <div  class="page" class="form-element-page" id="form-${form.id}-element-page-1">
                    <div class="formSectionTittle" id="$form-{form.id}-tittle-page-1">${form.name}</div>
                    <div class="formSectionText" id="form-${form.id}-text-page-1">
                        <p>Państwa odpowiedź na poniższe 7 pytań i zaufanie w przekazaniu kontaktu do Państwa znajomych wynagrodzi moją pracę na dzisiejszym spotkaniu.</p>
                        <p>Proszę odpowiedzieć na pytanie zaznaczając „V” w skali od 1-10. W zależności od Państwa wewnętrznej oceny. Proszę o szczerość.</p>
                    </div>
                    <c:set var="x" value="0"/>
                    <c:forEach items="${questions}" var="question">
                        <!--change following if to the if checking the type of the question-->
                        <c:if test="${x<=6}">
                             <c:set var="errorKey" value="question-${question.id}"/>
                                    
                            <div  class="formSectionQuestion" id="form-${form.id}-element-question-${question.id}">
                                <div  class="formSectionQuestionText">${question.question}<br/><span class="formErrorMessage">${errors[errorKey]}</span></div>
                                <div  class="formSectionQuestionDescription">${question.description}</div>
                                <input type="hidden" name="question-${question.id}-type" value="radio"/>
                                <div  class="formSectionQuestionBody">
                                    <table border="1" align="center">
                                        <tr>
                                            <c:forEach var="value" begin="1" end="10">
                                                <c:set var="selected" value=""/>
                                                <c:set var="valueKey" value="question-${question.id}"/>
                                                <c:if test="${value eq (rparams[valueKey])[0]}">
                                                    <c:set var="selected" value="checked"/>    
                                                </c:if>

                                                <td><input type="radio" name="question-${question.id}" value="${value}" ${selected}/></td> 
                                            </c:forEach>
                                        </tr><tr>
                                            <c:forEach var="value" begin="1" end="10">
                                                <td>${value}</td>
                                            </c:forEach>
                                            
                                        </tr>
                                    </table>
                                   
                                </div>
                            </div>
                        </c:if>
                        <c:set var="x" value="${x+1}" scope="page"/>
                    </c:forEach>

                    <div class="formSectionTittle">TABELA REFERENCJI</div>
                    <div class="formSectionText">
                        <p>Rynek finansowy w Polsce potrzebuje profesjonalistów, których z zaufaniem możemy polecić osobom, 
                        które nie dysponują szeroką wiedzą finansową, aby samodzielnie podejmować słuszne decyzje 
                        dotyczące ich finansów.</p>
                        <p>Jeżeli odczuwają Państwo satysfakcję ze spotkania ze mną, to proszę ułatwić mi dotarcie do osób, 
                            które mogą potrzebować mojej wiedzy i kompetencji.</p>
                        <p>Proszę o kontakt do od 2 do 5 osób, które poinformuje Pani/Pan o fakcie naszego spotkania i 
                        uprzedzi Pani/Pan przed moim kontaktem z nimi tak, aby nie czuły się urażone za przekazanie danych 
                        osobowych.</p>
                    </div>
                    <div class="formSectionQuestion" id="form-${form.id}-element-question-${question.id}">
                        <div class="formSectionQuestionText">${question.question}</div>
                        <div class="formSectionQuestionDescription">${question.description}</div>
                        <div class="formSectionQuestionBody">
                            <table cellspacing="0" cellpadding="0" style="margin-left:auto;margin-right: auto;">

                                <tr>
                                    <th>Nazwisko</th>
                                    <th>Imie</th>
                                    <th>Telefon</th>
                                    <th>Email</th>
                                    <th>&nbsp;</th>
                                    <th>&nbsp;</th>
                                </tr>
                                <c:set var="x" value="0" scope="page"/>
                                <c:forEach items="${questions}" var="question">
                                    <c:if test="${x<=6}">

                                    </c:if>
                                    <c:if test="${x>6}">
                                        <tr>
                                            <c:set var="valueKey" value="question-${question.id}"/>
                                            <td><input style="width:120px" type="text" maxlength="255" name="question-${question.id}" value="${(rparams[valueKey])[0]}"/></td>
                                            <td><input style="width:120px" type="text" maxlength="255" name="question-${question.id}" value="${(rparams[valueKey])[1]}"/></td>
                                            <td><input style="width:120px" type="text" maxlength="255" name="question-${question.id}" value="${(rparams[valueKey])[2]}"/></td>
                                            <td><input style="width:120px" type="text" maxlength="255" name="question-${question.id}" value="${(rparams[valueKey])[3]}"/></td>
                                            <td><input type="hidden" name="question-${question.id}-type" value="grid"/></td>
                                            <c:set var="errorKey" value="question-${question.id}"/>
                                            <td class="formErrorMessage">${errors[errorKey]}</td>
                                        </tr>
                                    </c:if>
                                    <c:set var="x" value="${x+1}" scope="page"/>
                                </c:forEach>
                            </table>
                        </div>
                    </div>
                </div>
                <div style="text-align:right;position:relative;" class="row form-button-container">
                   <!-- <input class="formCancelButton" type="reset" value="Anuluj formularz"/>-->
                    <input class="formSubmitButton" type="submit" value="Wyślij formularz"/>
                </div>

            </div>

        </form>
        </div>
    </body>
</html>
